/**
 *
 */
package com.ybkj.daijia.server.service.impl;

import com.ybkj.daijia.common.Pager;
import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.page.Pageable;
import com.ybkj.daijia.page.impl.PageImpl;
import com.ybkj.daijia.page.impl.PageRequest;
import com.ybkj.daijia.server.mapper.MemberApplyMapper;
import com.ybkj.daijia.server.model.MemberApply;
import com.ybkj.daijia.server.service.MemberApplyService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Shine
 *
 */
@Service
public class DefaultMemberApplyService implements MemberApplyService {

    @Autowired
    private MemberApplyMapper memberApplyMapper;

    /* (non-Javadoc)
     * @see com.ybkj.shop.service.AdminService#queryAll()
     */
    public Page<MemberApply> queryAll() {

        Pageable pageable = new PageRequest(Pager.getPage(), Pager.getLimit());

        List<MemberApply> content = memberApplyMapper
            .selectAll(Pager.getOffset(), Pager.getLimit());
        long total = memberApplyMapper.countAll();

        return new PageImpl<MemberApply>(content, pageable, total);
    }

    @Transactional(rollbackFor = Exception.class)
    public MemberApply insertRecord(MemberApply memberApply) {

        memberApplyMapper.insertRecord(memberApply);

        return memberApply;
    }

    public MemberApply findOne(Long id) {

        return memberApplyMapper.selectByPrimaryKey(id);
    }


    @Transactional(rollbackFor = Exception.class)
    public void delete(MemberApply memberApply) {

        memberApplyMapper.deleteByPrimaryKey(memberApply.getId());

    }


    @Override
    public MemberApply findByPhone(String phone) {

        return memberApplyMapper.selectByPhone(phone);
    }

    @Override
    public long countAll() {

        return memberApplyMapper.countAll();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateByPrimaryKey(MemberApply record) {

        return memberApplyMapper.updateByPrimaryKey(record);
    }

}